package com.zgjkhis.modules.system.service.mapper;

import com.zgjkhis.common.mapper.CoreMapper;
import com.zgjkhis.modules.registration.service.dto.ConsultDto;
import com.zgjkhis.modules.registration.service.dto.ConsultQueryCriteria;
import com.zgjkhis.modules.system.domain.Consult;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author yzq
 * @Description 处方
 * @Date 2021/6/23 9:48
 * @Param
 * @return
 **/
@Repository
public interface ConsultMapper extends CoreMapper<Consult> {


    /**
     * @Author yzq
     * @Description 分页查询挂号信息
     * @Date 2021/9/6 10:46
     * @Param [criteria]
     * @return java.util.List<com.zgjkhis.modules.registration.service.dto.ConsultDto>
     **/
    @Select("<script>select t.*,a.age,a.sex,a.phone from (select * from his_consult where consult_flag &lt; 3) t \n" +
            " left join his_account a on t.patient_id=a.id \n" +
            " where 1=1 and t.pharmacy_id=#{consult.pharmacyId}\n" +
            "<if test=\"consult.name!=null and consult.name!=''\">\n" +
            "\t and t.patient_name LIKE concat('%', #{consult.name}, '%')  or RIGHT (a.phone,4)=#{consult.name}\n" +
            "</if>\n" +
            "<if test=\"consult.departId!=null and consult.departId!=''\">\n" +
            "\t and t.consult_depart_id=#{consult.departId}\n" +
            "</if>\n" +
            "<if test=\"consult.consultType!=null and consult.consultType != '0' \">\n" +
            "\t and t.consult_type=#{consult.consultType}\n" +
            "</if>\n" +
            "<if test=\"consult.consultStatus!=null and consult.consultStatus != '0' \">\n" +
            "\t and t.consult_status=#{consult.consultStatus}\n" +
            "</if>\n" +
            "<if test=\"consult.consultDocId !=null and consult.consultDocId != '' \">\n" +
            "\t and t.consult_doc_id=#{consult.consultDocId}\n" +
            "</if>\n" +
            "<if test=\"consult.startTime !=null \">\n" +
            "\t and t.create_time  &gt; #{consult.startTime}\n" +
            "</if>\n" +
            "<if test=\"consult.endTime!=null \">\n" +
            "\t and t.create_time    &lt;  str_to_date(DATE_ADD(#{consult.endTime},INTERVAL 1 DAY), '%Y-%m-%d %H')\n" +
            "</if>\n" +
            "\n</script>")
    List<ConsultDto> findAllByPageable(@Param("consult") ConsultQueryCriteria criteria);
}
